import {ComponentOptions, defineAsyncComponent, PropType} from "vue";
import {TableConfigItem} from "../types";
import type DynamicTable from "../index.vue";


export const BaseCommonMixin: ComponentOptions = {
    components: {
        RenderVnodes: defineAsyncComponent(() => import('../../../components/RenderVnodes3/index.vue')),
    },
    props: {
        tableData: {
            type: Array,
            default: []
        },
        item: {
            type: Object as PropType<TableConfigItem>,
            default: {}
        },
        tableVm: {
            type: Object as PropType<ComponentOptions<typeof DynamicTable>>
        }
    },
    methods: {
        slotName(name) {
            let p = this.item.slotName || this.item.prop
            return p + '_' + name
        },
        hasSlotName(name) {
            const slot = this.tableVm.$slots[this.slotName(name)];
            return !!slot
        },
        slot(name, props) {
            const slot = this.tableVm.$slots[this.slotName(name)];
            return slot(props)
        }
    }
}